package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "订单管理接口")
@Slf4j
@RestController("adminOrderController")
@RequestMapping("/admin/order")
public class OrderController {


    @Autowired
    private OrderService orderService;

    /**
     * 订单搜索
     * @param pageQueryDTO
     * @return
     */
    @GetMapping("/conditionSearch")
    @ApiOperation("订单搜索")
    public Result<PageResult> conditionSearch(OrdersPageQueryDTO pageQueryDTO){
        log.info("订单搜索:{}",pageQueryDTO);
        PageResult pageResult = orderService.getOrdersByPageQuery(pageQueryDTO);
        return Result.success(pageResult);
    }


    /**
     * 各个状态的订单数量统计
     * @return
     */
    @ApiOperation("各个状态的订单数量统计")
    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> getOrderStatistics() {
        OrderStatisticsVO orderStatisticsVO = orderService.getOrderStatistics();
        return Result.success(orderStatisticsVO);
    }


    @PutMapping("/cancel")
    @ApiOperation("取消订单")
    public Result cancelOrder (@RequestBody OrdersCancelDTO ordersCancleDTO) {
        log.info("取消订单:{}",ordersCancleDTO);
        orderService.cancelOrder(ordersCancleDTO);
        return Result.success();
    }


    @ApiOperation("接单")
    @PutMapping("/confirm")
    public Result confirmOrder (@RequestBody OrdersConfirmDTO confirmDTO) {
        log.info("接单:{}",confirmDTO);
        orderService.confirmOrder(confirmDTO);
        return Result.success();
    }

    /**
     * 查询订单详情
     * @param id
     * @return
     */
    @ApiOperation("查询订单详情")
    @GetMapping("/details/{id}")
    public Result<OrderVO> getOrderDetail (@PathVariable Long id) {
        log.info("查询订单详情:{}",id);
        OrderVO orderVO = orderService.getOrderDetail(id);
        return Result.success(orderVO);
    }


    /**
     * 拒单
     * @param rejectionDTO
     * @return
     */
    @ApiOperation("拒单")
    @PutMapping("rejection")
    public Result rejectOrder (@RequestBody OrdersRejectionDTO rejectionDTO) {
        log.info("商户拒单:{}",rejectionDTO);
        orderService.rejectOrder(rejectionDTO);
        return Result.success();
    }


    /**
     * 派送订单
     * @param id
     * @return
     */
    @ApiOperation("派送订单")
    @PutMapping("/delivery/{id}")
    public Result deliveryOrder(@PathVariable Long id) {
        log.info("派送订单:{}",id);
        orderService.deliveryOrder(id);
        return Result.success();
    }


    @PutMapping("complete/{id}")
    public Result completeOrder(@PathVariable Long id) {
        log.info("订单完成:{}",id);
        orderService.completeOrder(id);
        return Result.success();
    }



}
